package com.hnjd.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hnjd.entity.Admins;
import com.hnjd.entity.Items;
import com.hnjd.entity.Orders;
import com.hnjd.entity.Types;
import com.hnjd.entity.User;
import com.hnjd.entity.Users;

public interface AdminDao {

	//登录
	@Select("select * from admins where username=#{username} and password=#{password}")
	List<Admins> login(Admins ad);
	
	//订单查询
		@Select("select * from orders")
		List<Orders> ordersList();

		@Select("SELECT items.* ,goods.id ,goods.name FROM items LEFT JOIN goods ON items.`good_id` = goods.`id` WHERE order_id =  #{orderId}")
		@Results({
			@Result(property = "goods.id",column = "id" ),
			@Result(property = "goods.name",column = "name")
		})
		List<Items> itemList(Integer orderId);

		@Select("select * from users where id = #{userId}")
		User getUserById(Integer userId);
		
		//根据状态订单查询
		@Select("select * from orders where status = #{status}")
		List<Orders> ordersListByStatus(Integer status);

		//根据id删除订单
		@Delete("delete  from orders where id = #{id}")
		Integer orderDelete(Integer id);
		
		//修改订单状态
		@Update("update orders set status=#{param1} where id=#{param2}")
		Integer orderUpdate(Integer status,Integer id);
		
		//类目全查询
		@Select("select * from types")
		List<Types> typeList();
		
		//类目添加
		@Insert("insert into types values(null,#{name},#{num})")
		Integer typeAdd(Types types);
		
		//类目id查询
		@Select("select * from types where id=#{id}")
		Types typeEditById(Integer id);
		
		//类目修改
		@Update("update types set name=#{name},num=#{num} where id=#{id}")
		Integer typeUpdate(Types types);
		
		//类目删除
		@Delete("delete from types where id=#{id}")
		Integer typeDelete(Integer id);
		
		//客户查询
		@Select("select * from users")
		List<Users> userList();
		
		//客户添加
		@Insert("insert into users values(null,#{username},#{password},#{name},#{phone},#{address})")
		Integer userAdd(Users users);
		
		//客户重置密码
		@Update("update users set password=#{password} where id=#{id}")
		Integer userReset(Users users);
		
		//客户查询id
		@Select("select * from users where id=#{id}")
		Users userEdit(Integer id);
		
		//客户修改
		@Update("update users set username=#{username},name=#{name},phone=#{phone},address=#{address} where id=#{id}")
		Integer userUpdate(Users users);
	
		//客户删除
		@Delete("delete from users where id=#{id}")
		Integer userDelete(Integer id);
		
		//管理员查询
		@Select("select * from admins")
		List<Admins> adminList();
		
		//管理员重置密码
		@Update("update admins set password=#{password} where id=#{id}")
		Integer adminReset(Admins admins);
		
		//管理员添加
		@Insert("insert into admins values(null,#{username},#{password})")
		Integer adminAdd(Admins admins);
		
		//管理员删除
		@Delete("delete from admins where id=#{id}")
		Integer adminDelete(Integer id);
}
